import React from "react";
import { Modal, message } from "antd";
import { ExclamationCircleOutlined } from "@ant-design/icons";
import { postRequest } from "../utils/http";

function ConfirmModal(props) {
  const { visible, setVisible, setIsUpdate, actionData, infoFields } = props;
  const modalText = "删除";
  /* 确认按钮 */
  const confirm = () => {
    setVisible(true);
    /* 接口请求 */
    postRequest(actionData.url).then(data => {
      message.success(`${data[infoFields]}资源数据删除成功`);
      setIsUpdate(new Date().getTime());
      setVisible(false);
    });
  };
  /* 取消按钮 */
  const cancel = () => {
    setVisible(false);
  };

  return (
    <Modal title="Modal" visible={visible} onOk={confirm} onCancel={cancel} okText="确认" cancelText="取消">
      <ExclamationCircleOutlined style={{ color: "red", fontSize: "18px" }} />
      <span style={{ paddingLeft: "10px" }}>{`您确认定${modalText} ${actionData && actionData[infoFields]} ?`}</span>
    </Modal>
  );
}

export default ConfirmModal;
